package edu.chinasoft.service;

import edu.chinasoft.domain.User;
import edu.chinasoft.exception.MapperException;
import edu.chinasoft.exception.ServiceException;
import edu.chinasoft.mapper.UserMapper;
import jdk.internal.org.objectweb.asm.tree.TryCatchBlockNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.NestedRuntimeException;

public class UserServiceImp implements  UserService {
    private UserMapper userMapper;
    private Logger logger = LoggerFactory.getLogger(UserServiceImp.class);

    @Override
    public void registerUser(User user) {
        userMapper.insertTable(user);
    }

    @Override
    public User loginUser(User user){
        logger.debug("UserServiceImp>>>loginUser start ……");
        User result=null;
        try {
            result = userMapper.selectTableByNameAndPassword(user);
        }catch(NestedRuntimeException e){
            throw new MapperException(e);
        } catch (Exception e){
            throw new ServiceException(e);
        }
        logger.debug("UserServiceImp>>>loginUser end ……");
        return result;
    }



    public UserMapper getUserMapper() {
        return userMapper;
    }

    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }
}
